package com.example.demo.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Home-pc
 * Date: 2024-02-22
 * Time: 20:50
 */
@Slf4j
@Aspect
//@Component
public class AspectDemo {

    @Pointcut("execution(* com.example.demo.controller.*.*(..))")
    public void pt(){

    }

    @Before("pt()")
    public void doBefore(){
        log.info("执行AspectDemo before");
    }

    @After("pt()")
    public void doAfter(){
        log.info("执行AspectDemo After");
    }

    @AfterReturning("execution(* com.example.demo.controller.*.*(..))")
    public void doAfterReturning(){
        log.info("执行AspectDemo AfterReturning");
    }

    @AfterThrowing("execution(* com.example.demo.controller.*.*(..))")
    public void doAfterThrowing(){
        log.info("执行AspectDemo AfterThrowing");
    }

    @Around("execution(* com.example.demo.controller.*.*(..))")
    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("执行AspectDemo doAround前");
        Object result = joinPoint.proceed();
        log.info("执行AspectDemo doAround后");
        return result;
    }

}
